package pod

import (
	"context"
	"krm-backend/config"
	"krm-backend/controllers"
	"krm-backend/utils/logs"

	"github.com/gin-gonic/gin"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func Delete(r *gin.Context) {
	logs.Debug(nil, "删除pod")
	clientset, basicInfo, err := controllers.BasicInit(r, nil)
	returnData := config.ReturnData{}
	if err != nil {
		returnData.Status = 400
		returnData.Message = err.Error()
		r.JSON(200, returnData)
		return
	}
	logs.Warning(map[string]interface{}{"deleteList": basicInfo.DeleteList}, "删除多个数据")
	for _, v := range basicInfo.DeleteList {
		_ = clientset.CoreV1().Pods(basicInfo.Namespace).Delete(context.TODO(), v, metav1.DeleteOptions{})
	}
	returnData.Status = 200
	returnData.Message = "删除成功"
	r.JSON(200, returnData)
}
